package com.javasm.aftersales;

import com.javasm.commons.base.BaseController;
import com.javasm.commons.entity.AxiosResult;
import com.javasm.commons.entity.TableDatas;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

/**
 * @author:Dai
 * @className:RepairController
 * @description: 维修点管理
 * @date:2022/9/23 10:42
 * @version: 1.0
 * @since: jdk11
 */
@RestController
@RequestMapping("repair")
public class RepairController extends BaseController {


    @Autowired
    private  RepairService repairService;

    @GetMapping("repTree")//查询树形菜单
    public AxiosResult getBuildTree(){
        Collection<RepairType> tree = repairService.getTree();
        return  suc(tree);
    }

    @GetMapping("getList")
    public TableDatas getAll(Repair repair){
        startPage();
        List<Repair> list = repairService.getList(repair);
        return new TableDatas(list);
    }

    @GetMapping("select")
    public TableDatas selectAll(Repair repair){
        startPage();
        List<Repair> repairs = repairService.selectAll(repair);
        return new TableDatas(repairs);
    }
    @PostMapping("insert")
    public AxiosResult insert(@RequestBody Repair repair){
        Integer flag = repairService.insertRep(repair);
        return isok(flag==1);

    }
    @PutMapping("update")
    public AxiosResult update(@RequestBody Repair repair){
        Integer flag = repairService.updateRep(repair);
        return isok(flag==1);
    }
    @DeleteMapping("deleteByIds/{id}")
    public AxiosResult deleteByids(@PathVariable("id")  List<Integer> id){
        Integer flag = repairService.deleteReps(id);
        return isok(flag==id.size());
    }
    @DeleteMapping("deleteById/{id}")
    public AxiosResult deleteByid(@PathVariable("id") Integer id){
        Integer flag = repairService.deleteRep(id);
        return isok(flag==1);
    }


}
